﻿using IDLETD.Agent;
using IDLETD.FSM;
using IDLETD.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace IDLETD.UserControls
{
    /// <summary>
    /// BulletControl.xaml 的交互逻辑
    /// </summary>
    public partial class BulletControl : BaseControl
    {
        #region 依赖属性
        public override BaseGameObject DataInfo
        {
            get { return (BaseGameObject)GetValue(BulletProperty); }
            set { SetValue(BulletProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Monster.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BulletProperty =
            DependencyProperty.Register("DataInfo", typeof(BaseGameObject), typeof(BulletControl), new PropertyMetadata(null, (sender, e) =>
            {
                var dp = sender as BulletControl;
                if (dp == null) return;
                dp.GetDataContent();
            }));
        #endregion

        public event Action<BulletControl> Remove;


        #region 变量
        SportAgent sportAgent = new SportAgent();
        public CrashAgent crashAgnet = new CrashAgent();
        #endregion

        private void GetDataContent()
        {
            DataContext = DataInfo;
            sportAgent.Onwer = DataInfo;
            DataInfo.PropertyChanged += Bullet_PropertyChanged;
            DataInfo.RegisterState(StateEnum.空闲, new StateIdle() { Onwer = DataInfo, SportAgent = sportAgent });
            DataInfo.RegisterState(StateEnum.追击, new StateFollow() { Onwer = DataInfo, SportAgent = sportAgent });
            DataInfo.RegisterState(StateEnum.死亡, new StateDead() { Onwer = DataInfo, SportAgent = sportAgent, CrashAgent = crashAgnet });
            DataInfo.GoIdle();
        }

     

        public BulletControl()
        {
            InitializeComponent();
        }

        private void Bullet_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case "X":
                    Canvas.SetLeft(this, DataInfo.X);
                    break;
                case "Y":
                    Canvas.SetTop(this, DataInfo.Y);
                    break;
            }
        }

    }
}
